package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhangs
 * @version v1.0
 * @decription Servlet 1
 * @date 2021/3/23 20:46
 **/
@WebServlet("/demo01")
public class Demo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // 往Request域中存放数据
        req.setAttribute("name", "世界");
        // 进行请求转发
        req.getRequestDispatcher("/demo02").forward(req, resp);
        // 打印出Demo01中存储的数据
        System.out.println("Demo01中获取Demo01中存储的数据：" +
                req.getAttribute("name"));
        // 打印出在Demo02中存储的数据
        System.out.println("Demo01中获取Demo02中存储的数据：" +
                req.getAttribute("age"));
    }
}
